﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PreeRegisterModel;
using System.Data;
using PreeRegisterDAL;
using PreeRegisterBLL.Security;
using DrSoftsFrame;

namespace PreeRegisterBLL
{
    public class OrderCompareBLL
    {
        /// <summary>
        /// 订单比对查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static OrderCompareResponseModel GetOrderCompare(OrderCompareRequestModel request)
        {
            try
            {
                //查询排班号源
                OrderCompareResponseModel OrderCompareResponseModel = new PreeRegisterModel.OrderCompareResponseModel();

                string strwhere = "";

                //增加同煤版  liujia150812
                if (VariableBLL.IFTmkyy)
                {
                    strwhere = " where len(cPreRegisterCode)>=11 and len(cPreRegisterCode)<=13 ";
                }
                else
                {
                    strwhere = " where len(cPreeCode)>=11 and len(cPreeCode)<=13 ";
                }                

                if (request.wid!=null&&request.wid.Trim() != "")
                {
                    strwhere += " and iworkplanid=" + request.wid.Trim();
                }

                if (request.starttime != null && request.starttime.Trim() != "")
                {
                    DateTime starttime = timestamp.StampToDateTime(request.starttime.Trim());
                    strwhere += " and dUpdate>='" + starttime.ToString()+ "'";
                }

                if (request.endtime != null && request.endtime.Trim() != "")
                {
                    DateTime endtime = timestamp.StampToDateTime(request.endtime.Trim());
                    strwhere += " and dUpdate<='" + endtime.ToString() + "'";
                }

                //增加同煤版参数  liujia150812
                DataSet ds = OrderCompareDAL.GetOrderCompareInfo(VariableBLL.IFTmkyy,strwhere);

                //赋值订单对比实体
                List<OrderCompareModel> OrderCompareModel_list = new List<OrderCompareModel>();

                //订单
                foreach (DataRow dropdregisterpree in ds.Tables["opdregisterpree"].Rows)
                {
                    OrderCompareModel orderCompareModel = new OrderCompareModel();

                    orderCompareModel.autoid = dropdregisterpree["iRegisterPreeNo"].ToString();
                    orderCompareModel.orderid = dropdregisterpree["cPreeCode"].ToString();
                    orderCompareModel.idcard = dropdregisterpree["cIdentityCard"].ToString();
                    orderCompareModel.state = dropdregisterpree["bRegisteFlag"].ToString();
                    orderCompareModel.resourceid = dropdregisterpree["iWorkPlanDetailId"].ToString();
                    orderCompareModel.tel = dropdregisterpree["cTel"].ToString();

                    OrderCompareModel_list.Add(orderCompareModel);
                }
             
                OrderCompareResponseModel.hospid = VariableBLL.HospitalId;
                OrderCompareResponseModel.endtime = Common.ToDateTime(ds.Tables["DtUpdate"].Rows[0]["dUpdate"]).ToString("yyyy-MM-dd HH:mm:ss");
                OrderCompareResponseModel.orders = OrderCompareModel_list;

                //返回
                return OrderCompareResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
